package com.k3cloud.conntroller;


import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;
import com.hustcad.plm.caddocapi.service.TyplmCADRelObjectService;
import com.k3cloud.service.ErpK3cloudService;
import com.k3cloud.user.service.ErpBomService;
import com.k3cloud.user.service.SettingService;
import com.ty.basic.response.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.UUID;

@RestController
@RequestMapping("/rest/v1/setting")
public class SettingController {

    @Autowired
    SettingService settingService;
    @Autowired
    ErpK3cloudService erpK3cloudService;
    @Autowired
    ErpBomService erpBomService;
    @Autowired
    TyplmCADRelObjectService typlmCADRelObjectService;


    @PostMapping("/add")
    public ResponseResult add(@RequestBody Map<String,Object> map) {
        map.put("id", UUID.randomUUID().toString());
        map.put("flag",1);
        map.put("executionType",1);
        map.put("useSystem","永续动力PLM");
        settingService.add(map);
        return ResponseResult.success();
    }

    @RequestMapping("/list")
    public ResponseResult<PageInfo<Map<String,Object>>> list(@RequestBody Map<String,Object> map) {
        PageMethod.startPage((Integer) map.get("pageNum"), (Integer) map.get("pageSize"), true);
        List<Map<String,Object>> list = settingService.list(map);
        PageInfo<Map<String,Object>> result = new PageInfo(list);
        return ResponseResult.success(result);
    }
    @RequestMapping("/edit")
    public ResponseResult edit(@RequestBody Map<String,Object> map) {
        settingService.edit(map);
        return ResponseResult.success();
    }
    @RequestMapping("/delete")
    public ResponseResult delete(@RequestBody Map<String,Object> map) {
        settingService.deleteSetting(map);
        return ResponseResult.success();
    }

    @RequestMapping("/logs")
    public ResponseResult<PageInfo<Map<String,Object>>> logs(@RequestBody Map<String,Object> map) {
        PageMethod.startPage((Integer) map.get("pageNum"), (Integer) map.get("pageSize"), true);
        List<Map<String,Object>> list = settingService.logs(map);
        PageInfo<Map<String,Object>> result = new PageInfo(list);
        return ResponseResult.success(result);
    }
    @RequestMapping("/deleteLogs")
    public ResponseResult deleteLogs(@RequestBody Map<String,Object> map) {
        settingService.deleteLogs(map);
        return ResponseResult.success();
    }

}
